<template>
	<!-- 购买结果 -->
	<view>
		<view class="top">
			<view class="item1">
				<view class="top1"><van-icon name="checked" /></view>
				<view class="">购买成功</view>
			</view>
			<view class="item2">请耐心等待审核</view>
			<view class="item3">
				<view class="" @click="gohome">返回首页</view>
				<view class="" @click="examine">查看订单</view>
			</view>
		</view>
		<view class="box">
			<view class="itemBox" v-for="item in list.data" :key="item.id" @click="getCommodityDetail(item.id)">
				<view class="item">
					<image :src="item.image_text" mode=""></image>
				</view>
				<view class="bottom">
					<view class="titletext xiankuan">{{item.name}}</view>
					<view class="xiaohuang margin_top1">积分:{{item.smallgoodsunit.priceinfo.buy_send_score}}分</view>
					<view class="flexbetween zdy">
						<!-- <view class="">库存:{{item.goods_num || 0}}</view> -->
						<view class="">月销{{item.mouth_sales || 0}}</view>
					</view>
					<view class="detail">
						<view class="price">￥{{item.smallgoodsunit.priceinfo.prev_xs_price?item.smallgoodsunit.priceinfo.prev_xs_price:item.smallgoodsunit.priceinfo.price || 0}}</view>
						<view class=""  @click.stop="addCart(item)">
							<uni-icons type="cart" size="24" color="rgb(245,172,79)"></uni-icons>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/commonFun/httpRequest.js");
	export default {
		data() {
			return {
				page: 1,
				limit: 10,
				list: {
					list: [],
				},
			};
		},
		onLoad() {
			this.getlist();
		},
		methods: {
			//跳转详情
			getCommodityDetail(i) {
				uni.navigateTo({
					url: '/pages/index/commodityDetail/commodityDetail?id=' + i,
				});
			},
			//添加购物车
			addCart(item) {
				let _this = this;
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: '/pages/login/logintwice'
					})
					return;
				}
				httpRequest.request('/customapi/cart/addCart', 'GET', {
					goods_id: item.id,
					number: 1,
					sku_id: item.smallgoodsunit.priceinfo.id
				}).then(res => {
					httpRequest.toast(res.msg)
				})
			},
			getlist(isPage, page) {
				let _this = this;
				httpRequest.request('/customapi/goods/index', 'POST', {
					category_id: "",
					page: page || 1,
					limit: _this.limit,
					keyword: "",
					is_scoredh: 0,
				}).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data.push(...resList.data);
						} else {
							_this.list = res.data;
							_this.list.data = resList.data;
						}
					} else {
						httpRequest.toast(res.msg);
					}
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.lastpage <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.getlist(true, page);
			},
			examine(id) {
				uni.navigateTo({
					url: '/pages/user/myOrder/myOrder?id=' + 1 + '&name=' + 1
				})
			},
			gohome() {
				uni.switchTab({
					url: '/pages/index/index',
				})
			},
		}
	};
</script>

<style scoped lang="scss">
	.box {
		padding: 20rpx 23rpx;
		flex-wrap: wrap;
		display: flex;
		justify-content: space-between;

		.itemBox {
			position: relative;
			width: 340rpx;
			font-size: 0;
			margin: 20rpx 0;
			border-radius: 25rpx 25rpx 25rpx 0;
			background: #ffffff;

			.item {
				image {
					width: 340rpx;
					height: 340rpx;
					border-radius: 25rpx 25rpx 0px 0px;
					background: #ffffff;
				}
			}

			.bottom {
				padding: 30rpx;
				background: #ffffff;

				.title {
					font-size: 32rpx;
					font-family: PingFang SC;
					font-weight: 800;
					color: #333333;
				}

				.detail {
					margin-top: 29rpx;
					font-size: 32rpx;
					font-family: PingFang SC;
					font-weight: 800;
					color: #FF0000;
					display: flex;
					justify-content: space-between;

					view {
						image {
							width: 30rpx;
							height: 30rpx;
						}
					}
				}
			}

		}
	}

	.top {
		height: 385rpx;
		background-color: #f5ac4f;
		overflow: hidden;
		color: #ffffff;

		.item1 {
			margin-top: 77rpx;
			text-align: center;
			font-size: 48rpx;
			font-family: PingFang SC;
			font-weight: 800;
			display: flex;
			justify-content: center;

			.top1 {
				margin-right: 10rpx;
			}
		}

		.item2 {
			margin-top: 45rpx;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 800;
			text-align: center;
		}

		.item3 {
			margin-top: 46rpx;
			display: flex;
			justify-content: space-around;
			padding: 0 40rpx;

			view {
				border-radius: 44px;
				border: 2px solid #ffffff;
				padding: 22rpx 54rpx;
				font-size: 32rpx;
				font-weight: bold;
			}
		}
	}
</style>